package com.cskaoyan.market.controller.wx;

import com.cskaoyan.market.service.wx.WxGoodsDetailService;
import com.cskaoyan.market.util.ResponseUtil;
import com.cskaoyan.market.vo.wx.lhh.homeIndexVo.NewHotGoodsListVo;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.session.Session;
import org.apache.shiro.subject.Subject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

/**
 * @ClassName WxGoodsController
 * @Description
 * @Author MZ
 * @Date 2023/5/21 15:21
 */
@RestController
@RequestMapping("wx/goods")
public class WxGoodsDetailController {

    @Autowired
    WxGoodsDetailService wxGoodsService;


    /**
     * @MethodName detail
     * @Description  商品详情页
     * @param: id   商品id，goods表id
     * @return: java.lang.Object
     * @Author MZ
     * @Date 15:25 2023/5/21
     **/
    @GetMapping("detail")
    public Object detail(Integer id){
        // /wx/goods/detail?id=1181000
        Subject subject = SecurityUtils.getSubject();
        Session session = subject.getSession();
        Integer userId = (Integer) session.getAttribute("userId");

        Map<String,Object> result = wxGoodsService.getGoodsDetail(id,userId);

        return ResponseUtil.ok(result);
    }

    @GetMapping("related")
    public Object related(Integer id){
        // /wx/goods/related?id=1181000

        List<NewHotGoodsListVo> result = wxGoodsService.getGoodsRelated(id);

        return ResponseUtil.okList(result);
    }

}
